import React from 'react';
import myAxios from '../service/myAxios'
import 'antd/dist/antd.css';
import { Form, Input, Button, Select,message } from 'antd';
const { Option } = Select;
const layout = {
  labelCol: {
    span: 8,
  },
  wrapperCol: {
    span: 16,
  },
};
const tailLayout = {
  wrapperCol: {
    offset: 8,
    span: 16,
  },
};

 const AddUser= () => {
  const [form] = Form.useForm();



  const onFinish = (values) => {
        const user={
        username:values.username,
        password:values.password,
        name:values.name,
        sex:values.sex
	}
  myAxios.post("test/addUser",user)
  .then(data=>{
          if(data.code===2001){
            message.success (data.message)
          }
  })

    // .catch(err => console.log(err))
  };

  const onReset = () => {
    form.resetFields();
  };

  const onFill = () => {
    form.setFieldsValue({
      username: 'wuming',
	  password:'123',
	  name:'无名',
      sex: '1'
    });
  };

  return (
    <Form {...layout} form={form} name="control-hooks" onFinish={onFinish}>
      <Form.Item
        name="username" label="用户名"
        rules={[ { required: true,}, ]}
      >
        <Input 		style={{width:"200px"}}/>
      </Form.Item>
	  <Form.Item
        name="password" label="密码"
        rules={[ { required: true,}, ]}
      >
        <Input 		style={{width:"200px"}}/>
      </Form.Item>
	  <Form.Item
        name="name" label="名字"
        rules={[ { required: true,}, ]}
      >
        <Input 		style={{width:"200px"}}/>
      </Form.Item>

      <Form.Item
        name="sex"
        label="性别"
        rules={[
          {
            required: true,
          },
        ]}
      >
        <Select
          allowClear
		  style={{width:"200px"}}
        >
          <Option value="1">男</Option>
          <Option value="2">女</Option>
        </Select>
      </Form.Item>

      <Form.Item {...tailLayout}>
        <Button type="primary" htmlType="submit">
           提交
        </Button>
        <Button htmlType="button" onClick={onReset}>
			重置
        </Button>
        <Button type="link" htmlType="button" onClick={onFill}>
          随机填充
        </Button>
      </Form.Item>
    </Form>
  );
};

export default AddUser;